import request from '@/utils/request'

function url(u) {
  const prefix = '/meetingmember'
  return `${prefix}${u || ''}`
}

export function findMeetingMember(id) {
  return request({
    url: url(`/${id}`),
    method: 'get'
  })
}

/**
 *
 * @param {number} mid
 * @param {Array} members
 */
export function deleteMeetingMember(mid, members) {
  const data = { mid, members }
  return request({
    url: url('/delete'),
    method: 'post',
    data: data
  })
}

// 通过邀请码加入会议
export function joinMeetingByCode(mid, invitationCode) {
  const data = {
    mid,
    invitationCode
  }
  return request({
    url: url('/invitationCode'),
    method: 'post',
    data: data
  })
}

export function inviteMember(mid, members) {
  const data = {
    mid,
    members
  }
  return request({
    url: url(),
    method: 'post',
    data: data
  })
}

export function acceptInvitation(id) {
  return request({
    url: url(`/${id}`),
    method: 'put'
  })
}
